#include <stdio.h>
#include <string.h>

#define BUFFER_SIZE 10


/* 找到数组的最小值 */
int findNumMinVal(int *nums, int numSize, int *pos)
{
    int adx = 0;
    int jdx = 1;
    for(int idx = 0; idx < numSize; idx++)
    {
        if(nums[idx] > nums[adx])
        {
            *pos = adx;
        }
        else
        {
            *pos = idx;
            adx = idx;  
        }
    }
    /* 返回最小值 */
    return nums[adx];
}


/* 交换器 */
int swapNum(int *val1, int *val2)
{
    int tempVal = *val1;
    *val1 = *val2;
    *val2 = tempVal;
    return 0;
}

/* 打印 */
int printfNums(int *nums, int numsSize)
{
    for(int idx = 0; idx < numsSize; idx++)
    {
        printf("%d\t", nums[idx]);
    }
    printf("\n");
}

/* 选择排序 */
int selectSort01(int *nums, int numsSize, int pos)
{ 
    // int pos1 = pos;

    for(int idx = 0; idx < numsSize; idx++)
    {
        /* 发现最小值 */
        findNumMinVal(nums + idx, numsSize - idx, &pos);

        swapNum(&(nums[idx]), &(nums[pos + idx]));

    }
    return 0;
}


int main()
{
    int pos = 0;
    int nums[] = {22, 6, 4, 66, 69, 42, 54};
    /* 
    int nums[BUFFER_SIZE] = {22, 33, 44, 66};
    有了BUFFER_SIZE数组就硬性给你分配了100的空间，若没有BUFFER_SIZE，
    你有多少就分配多少，前提是你不超过BUFFER_SIZE
    */
    int numsSize = sizeof(nums) / sizeof(nums[0]);
    //int numsSize = strlen(nums);

    int minNum = findNumMinVal(nums, numsSize, &pos);
    printf("pos:%d\n", pos);
    printf("minnum:%d\n", minNum);
    printf("numsSiz:%d\n", numsSize); 

    selectSort01(nums, numsSize, pos);
    //selectSort02(nums, numsSize);
    printfNums(nums, numsSize);  
    
    return 0;
}
